package net.anzhuo.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import net.anzhuo.common.entity.PaginationVO;
import net.anzhuo.common.enums.ResultEnum;
import net.anzhuo.common.utils.ExceptionUtil;
import net.anzhuo.common.utils.RedisUtil;
import net.anzhuo.dao.GsBaseMapper;
import net.anzhuo.entity.GsBase;
import net.anzhuo.entity.db.seniorsearch.GsParam;
import net.anzhuo.service.GsBaseService;

@Service
public class GsBaseServiceImpl implements GsBaseService {

	@Autowired
	private GsBaseMapper gsBaseMapper;

	@Override
	public PaginationVO<GsBase> getListWithPage(GsBase gsBase) {
		PaginationVO<GsBase> paginationVO = new PaginationVO<>();
		paginationVO.setList(gsBaseMapper.getListWithPage(gsBase));
		paginationVO.setTotalCount(gsBaseMapper.getCount(gsBase));
		paginationVO.setTotalPage((gsBaseMapper.getCount(gsBase) + gsBase.getPageSize() -1)  / gsBase.getPageSize());
		paginationVO.setPageNo(gsBase.getPageNo());
		return paginationVO;
	}

	@Override
	public GsBase getById(Long id) {
		return gsBaseMapper.getById(id);
	}

	@Override
	public List<GsBase> getList() {
		return gsBaseMapper.getList();
	}

	@Override
	public List<GsBase> getList(GsParam gsBase) {
		return gsBaseMapper.getListByQuery(gsBase);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void update(GsBase gsBase) {
		gsBaseMapper.update(gsBase);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void save(GsBase gsBase) {
		gsBaseMapper.save(gsBase);
	}

	@Override
	@Transactional(rollbackFor=Throwable.class)
	public void delete(Long id) {
		GsBase gsBase = gsBaseMapper.getById(id);
		if (gsBase == null) {
			ExceptionUtil.throwAppException(ResultEnum.ILLEGAL_OPERATION);
			return;
		}
		gsBaseMapper.update(gsBase);
	}

	@Override
	public GsBase getByMd5(String md5) {
		return gsBaseMapper.getByMd5(md5);
	}
	@Override
	public GsBase getByCreditCode(String creditCode) {
		return gsBaseMapper.getByCreditCode(creditCode);
	}
	@Override
	public GsBase getByName(String name) {
		GsBase gsBase = null;
		
		
		gsBase = gsBaseMapper.getByName(name);
		
		return gsBase;
	}
	
	@Override
	public List<GsBase> getByNameList(String name) {
		List<GsBase> gsBaselist = gsBaseMapper.getByNameList(name);	
		return gsBaselist;
	}

	@Override
	public List<GsBase> getByCreditCodeList(String creditCode) {
		// TODO Auto-generated method stub
		return gsBaseMapper.getByCreditCodeList(creditCode);
	}
}
